n = int(input())
x = list(map(int, input().split()))
f = list(map(int, input().split()))
num = []
for i in range(0, n):
    for j in range(0, n):
        if i == j:
            continue
        if f[j] != i or f[i] != j:
            num.append(x[i] ^ x[j])
print(max(num))
